
struct Solution {}

impl Solution {
  pub fn day_of_year(date: String) -> i32 {
    let month_days = [31,28,31,30,31,30,31,31,30,31,30,31];
    let raw: Vec<&str> = date.split('-').collect();
    let year = raw[0].parse::<i32>().unwrap();
    let month = raw[1].parse::<usize>().unwrap();
    let day = raw[2].parse::<i32>().unwrap();
    let is_leap_year = |y: i32, m : usize| y % 4 == 0 && month > 2;
    month_days[0 .. month - 1].iter().sum::<i32>() + day + if is_leap_year(year, month) { 1 } else { 0 }    
  }
}